package com.kitty.game.fight.artifact.passive;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.game.fight.bean.PlayerFightObject;
import com.kitty.game.fight.bean.SuperBossFightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.service.FightMessageService;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.artifact.ArtifactService;

/**
 * 法宝被动技能效果
 */
public abstract class ArtifactEffect {


    /**
     * 技能特效id
     */
    public abstract short getEffectId();

    public abstract ArtifactType getType();

    /**
     * 效果触发
     *
     * @param fight
     * @param member
     * @param params
     * @return
     */
    public abstract Object trigger(Fight fight, FightObject member, Object... params);

    /**
     * 检查生效的基础条件
     *
     * @param fight
     * @param actor
     * @return
     */
    protected boolean checkBaseCondition(Fight fight, FightObject actor) {
        if (!actor.isPlayer()) {
            return false;
        }
        // 当前回合我的法宝被别人的卸甲金葫禁锢了
        if (fight.isMyArtifactInvalid(actor.getId())) {
            return false;
        }
        PlayerFightObject playerObj = (PlayerFightObject) actor;
        ArtifactService artifactService = SpringUtils.getBean(ArtifactService.class);
        return getType().getName().equals(artifactService.getEquippedArtifact(playerObj.getRole()));
    }

    /**
     * 特效广播
     *
     * @param fight
     * @param member
     * @param params
     */
    public void broadCast(Fight fight, FightObject member, Object... params) {
        FightMessageService fightMessageService = SpringUtils.getBean(FightMessageService.class);
        FightMessageUtil.sendFightPackage(fight, fightMessageService.attackSkillEffect(member.getId(), getEffectId(), "", 0));
    }

    /**
     * 检查生效的基础条件
     *
     * @param fight
     * @param actor
     * @return
     */
    protected boolean checkSuperBossBaseCondition(Fight fight, FightObject actor) {
        if (!actor.isSuperBoss()) {
            return false;
        }
        // 当前回合我的法宝被别人的卸甲金葫禁锢了
        if (fight.isMyArtifactInvalid(actor.getId())) {
            return false;
        }
        SuperBossFightObject superBossObject = (SuperBossFightObject) actor;
        return superBossObject.hasArtifact(getType().getName());
    }

    /**
     * 超级boss是否触发法宝
     */
    protected Object tirggerSuperBoss(Fight fight, FightObject member, Object... params) {
        if (!checkSuperBossBaseCondition(fight, member)) {
            return false;
        }
        ArtifactService artifactService = SpringUtils.getBean(ArtifactService.class);
        return artifactService.getSuperBossArtifactRate(getType().getName(), (SuperBossFightObject) member);
    }
}
